﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cinemon;
using Cinemon.MySqlConnect;
using MySql.Data.MySqlClient;
using System.Data;
using System.Drawing;


public partial class ForgotPassword : BaseClass
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnSubmitUserName_Click(object sender, EventArgs e)
    {
        try
        {
            DatabaseManager dbm = new DatabaseManager();
            List<MySqlParameter> sqlParams = new List<MySqlParameter>();
            sqlParams.Add(new MySqlParameter("username", tbxUsername.Text));
            DataTable dtQuestion = dbm.ExecuteQuery("GetUserSecurityQuestion", sqlParams);

            if (dtQuestion != null && dtQuestion.Rows.Count > 0)
            {
                lblSecurityQuestion.Text = dtQuestion.Rows[0]["Question"].ToString();
                lblSecurityQuestion.ForeColor = Color.Black;
            }
            else
            {
                lblSecurityQuestion.Text = "This username does not exist.";
                lblSecurityQuestion.ForeColor = Color.Red;
            }
        }
        catch (Exception ex)
        {
            LogLibrary.EventLogger.Log.LogError(ex);
        }
    }

    protected void btnGetPassword_Click(object sender, EventArgs e)
    {
        try
        {
            DatabaseManager dbm = new DatabaseManager();
            List<MySqlParameter> sqlParams = new List<MySqlParameter>();
            sqlParams.Add(new MySqlParameter("username", tbxUsername.Text));
            sqlParams.Add(new MySqlParameter("answer", tbxAnswer.Text));
            DataTable dtPassword = dbm.ExecuteQuery("GetUserPassword", sqlParams);

            if (dtPassword != null && dtPassword.Rows.Count > 0)
            {
                lblPassword.Text = "Your password is: " + dtPassword.Rows[0]["user_password"].ToString();
                lblPassword.ForeColor = Color.Black;
            }
            else
            {
                lblPassword.Text = "Your answer is incorrect.";
                lblPassword.ForeColor = Color.Red;
            }
        }
        catch (Exception ex)
        {
            LogLibrary.EventLogger.Log.LogError(ex);
        }
    }

    protected void btnLogin_Click(object sender, EventArgs e)
    {
        ClientScript.RegisterStartupScript(this.GetType(), "Login", "window.location = 'Default.aspx';", true);
    }
}